<template>
	<div class="list">
		<van-pull-refresh v-model="isDownLoading" @refresh="onRefresh">
			<van-list v-model="isUpLoading" :finished="finished" :finished-text="finishedText" @load="onLoad">
				<div class="item" v-for="item in list" @click="godetail(item.titem_id)" :key="item.titem_id">
					<p :class="['van-row--flex van-row--justify-space-between', item.toi_status>=4?'cancel':'']">
						<span>订单编号：{{item.toi_sn}}</span>
						<span>{{oderstatusArry[item.toi_status]}}</span>
					</p>
					<div class="infobox van-row--flex ">
						<van-image width="140px" height="105px" fit="cover" :src="item.default_img" />
						<div class="info">
							<div class="title van-multi-ellipsis--l2">{{item.title}}</div>
							<div class="ic van-row--flex van-row--align-center">
								<van-icon name="underway-o" color="#323232" size="20px" />
								<span>{{item.date}}</span>
							</div>
							<div class="ic van-row--flex van-row--align-center">
								<van-icon name="jingqumenpiao" class-prefix="icon" color="#323232" size="20px" />
								<span> {{item.people_num}} 张</span>
							</div>
						</div>
					</div>
					<div class="btns  van-row--flex van-row--justify-space-between  van-row--align-center">
						<div class="price"><span>金额： </span><span
								class="money">￥{{item.discount_price>0?item.discount_price:0}}</span>
						</div>
						<div class="btnbox van-row--flex van-row--align-center">
							<div class="btn">查看详情</div>
							<div class="btn pay" v-if="item.toi_status==2">立即支付</div>
						</div>
					</div>
				</div>
			</van-list>
		</van-pull-refresh>
		<van-empty v-if="loading&&list.length==0" description="暂无活动订单" />
	</div>
</template>

<script>
	import {
		ActiveOrderLog
	} from '@/http/active'

	export default {
		name: "activelist",
		data() {
			return {
				isDownLoading: false,
				isUpLoading: false,
				finished: false,
				list: [],
				page: 0,
				limit: 10,
				loading: false,
				finishedText: '已经到底啦~',
				// 1预约成功，2待支付，3已参加，4人员不足已取消，5已取消，6已退款 7未付款已取消 10已过期
				oderstatusArry1: [{
						1: '预约成功'
					},
					{
						2: '待支付'
					},
					{
						3: '已参加'
					},
					{
						4: '人员不足已取消'
					},
					{
						5: '已取消'
					},
					{
						6: '已退款'
					},
					{
						7: '未付款已取消'
					},
					{
						10: '已过期'
					}
				],
				oderstatusArry: {
					1: '待检票',
					2: '待支付',
					3: '已检票',
					4: '已取消',
					5: '已取消',
					6: '已退款',
					7: '已取消',
					10: '已过期'
				}
			}
		},
		created() {
			// this._ActiveOrderLog()
			if (this.$route.query.api_token) {
				localStorage.setItem('api_token', this.$route.query.api_token);
			}
		},
		methods: {
			_ActiveOrderLog() {
				ActiveOrderLog(this.page, this.limit).then(res => {
					this.loading = true;
					if (res.status == 1) {
						if (this.list.length) { //当请求前有数据时 第n次请求
							if (this.isUpLoading) { // 上拉加载
								this.list = this.list.concat(res.data) //上拉加载新数据添加到数组中
								this.$nextTick(() => { //在下次 DOM 更新循环结束之后执行延迟回调
									this.isUpLoading = false //关闭上拉加载中
								})
								if (res.data.length < this.limit) { //没有更多数据
									this.finished = true //上拉加载完毕
								}
							} else {
								this.finished = true //上拉加载完毕
							}
							if (this.isDownLoading) { //关闭下拉刷新
								this.isDownLoading = false; //关闭下拉刷新中
								this.list = res.data; //重新给数据赋值
								if (this.finished) { //如果上拉加载完毕为true则设为false。解决上拉加载完毕后再下拉刷新就不会执行上拉加载问题
									this.finished = false
								}
							}
						} else {
							this.isUpLoading = false; //关闭下拉刷新中
							this.isDownLoading = false; //关闭下拉刷新中
							this.list = res.data;
							if (this.list.length < this.limit) {
								this.finishedText = ''
							}
						}
					} else {
						this.finished = true;
						this.finishedText = ''
					}
				})
			},
			onLoad() {
				this.page++;
				this.isUpLoading = true;
				this._ActiveOrderLog();
			},
			onRefresh() {
				this.isDownLoading = false;
				this.page = 0;
				this._ActiveOrderLog();
			},
			godetail(titem_id) {
				this.$router.push({
					path: '/active/orderdetail',
					query: {
						titem_id: titem_id
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.list {
		min-height: calc(100vh - 92px);
		background-color: #EEEEEE;
		padding: 20px 0 70px 0;

		.item {
			border-radius: 0px 0px 24px 24px;
			margin-bottom: 20px;
			background-color: #fff;

			p {
				background-color: #F17F2A;
				height: 80px;
				color: #fff;
				font-size: 30px;
				line-height: 80px;
				padding: 0 30px;

				&.cancel {
					background-color: rgba(241, 127, 42, .3);
					color: $fzColor;
				}
			}

			.infobox {
				padding: 20px 0;
				margin: 0 30px;
				border-bottom: 2px solid $bordercolor;

				/deep/ .van-image {
					margin-right: 22px;

					img {
						border-radius: 18px;
					}
				}

				.info {
					.title {
						color: $fzColor;
						font-size: 32px;
						min-height: 80px;
					}

					.ic {
						margin-bottom: 21px;

						span {
							font-size: 28px;
							color: $fzColor;
							margin-left: 21px;
						}
					}
				}
			}

			.btns {
				padding: 30px;

				.price {
					color: $fzColor;
					font-size: 30px;

					.money {
						font-size: 36px;
						color: $priceColor;
					}
				}

				.btnbox {
					.btn {
						width: 156px;
						height: 60px;
						border: 2px solid rgba(241, 127, 42, 1);
						border-radius: 12px;
						text-align: center;
						line-height: 60px;
						color: #F17F2A;

						&.pay {
							background-color: #F17F2A;
							color: #fff;
							margin-left: 30px;
						}
					}
				}
			}
		}
	}
</style>
